# Load Data
setwd("/users/josephphillips/Dropbox/COVID-19/Data/FC Data Repository")
df <- read.csv("Canada 1.csv",header=T,sep=",")

# Load GLMNet Function
run_LASSO <- function(data, yvar){
  
  set.seed(2334)
  
  var_quo <- enquo(yvar)
  
  ## select x variables 
  dat <- data %>%
    dplyr::select(university, agegroup, male, married, frequentchurch, region, left, right, ideology1, knowledge, nonwhite, polinterest, trust_healthgov, total_media_trust, hotspot)
  
  ## select y-variable
  out1 <- data %>% 
    dplyr::select(!!var_quo) %>% pull() # save as a vector instead of a data-frame to use model.matrix()
  
  merged1 <- cbind(out1, dat) %>% na.omit() ## merge and delete NA
  x1 <- model.matrix(out1 ~ ., data = merged1) ## make model matrix
  y1 <- merged1$out1 ## select y-variable from NA-deleted dataset
  mod1 <- cv.glmnet(x1, y1, alpha = 1, family = "gaussian") ## run lasso model
  coef <- coef(mod1) ## get coef  
  
  list(merged1, x1, y1, mod1, coef)
  
}

# Lasso Regressions
lasso.h1 <- run_LASSO(df,targeted_false) ## university, age 55-64, age 65+, male, frequent church, West, right party, ideology1, knowledge, nonwhite, political interest, health trust
lasso.rq1.false <- run_LASSO(df,nontargeted_false) # age 55-64, age 65+, frequent church, ideology, knowledge, nonwhite, political interest, health trust
lasso.rq1.false.noleak <- run_LASSO(df,nontargeted_false_noleak) # age 45-54, age 55-64, age 65+, frequent church, West, ideology, knowledge, nonwhite, political interest, health trust
lasso.rq1.true <- run_LASSO(df,nontargeted_true) # age 55-64, male, frequent church, Quebec, West, knowledge, health trust
lasso.canada.con_theory1 <- run_LASSO(df,accuracy_con_theory1) # age 65+, frequentchurch, ideology1, nonwhite, trust_healthgov
lasso.canada.con_theory5 <- run_LASSO(df,accuracy_con_theory5) # age 55-64, age 65+, frequentchurch, right, ideology1, knowledge, nonwhite, polinterest, trust_healthgov
lasso.canada.False1 <- run_LASSO(df,accuracy_False1) # age 55-64, age 65+, male, frequentchurch, west, ideology1, knowledge, nonwhite, trust_healthgov
lasso.canada.False4 <- run_LASSO(df,accuracy_False4) # age 55-64, age 65+, frequentchurch, quebec, ideology1, knowledge, nonwhite, trust_healthgov
lasso.canada.False2 <- run_LASSO(df,accuracy_False2) # N/A
lasso.canada.False3 <- run_LASSO(df,accuracy_False3) # frequentchurch, quebec, ideology1, knowledge, nonwhite, polinterest
lasso.canada.edge1 <- run_LASSO(df,accuracy_edge1) # age 55-64, age 65+, male, frequentchurch, quebec, west, ideology1, knowledge, nonwhite, polinterest, trust_healthgov
lasso.canada.con_theory2 <- run_LASSO(df,accuracy_con_theory2) # ideology1, trust_healthgov, university, age 65+, frequent church, nonwhite, political interest, total media trust
lasso.canada.f_cure_1 <- run_LASSO(df,accuracy_f_cure_1) # age 55-64, age 65+, male, frequentchurch, quebec, idoelogy1, knowledge, nonwhite, political interest, trust_healthgov
lasso.canada.f_cure_2 <- run_LASSO(df,accuracy_f_cure_2) # age 55-64, age 65+, frequentchurch, ontario, ideology1, nonwhite, political iterest, trust_healthgov
lasso.canada.f_cure_3 <- run_LASSO(df,accuracy_f_cure_3) # age 45, age 55, age 65+, frequent church, quebec, ideology1, knowledge, nonwhite, political interest, health trust
lasso.canada.True1 <- run_LASSO(df,accuracy_True1) # age 35, age 55-64, age 65+, male, frequentchurch, west, knowledge, trust_healthgov
lasso.canada.True2 <- run_LASSO(df,accuracy_True2) # age 55-64, age 65+, male, frequentchurch, quebec, west, knowledge, nonwhite, trust_healthgov
lasso.canada.True3 <- run_LASSO(df,accuracy_True3) # age 65+, frequentchurch, ideology1, trust_healthgov
lasso.canada.True4 <- run_LASSO(df,accuracy_True4) # age 65+, male, frequentchurch, quebec, ideology1, knowledge, trust_healthgov
lasso.canada.True5 <- run_LASSO(df,accuracy_True5) # Age 65+, male, frequent church, west, nonwhite, political interest, trust_healthgov
lasso.canada.True6 <- run_LASSO(df,accuracy_True6) #quebec, trust_healthgov
lasso.canada.change3 <- run_LASSO(df,accuracy_change3) # Age 65, male, frequent church, ideology, media trust, trust_healthgov
lasso.canada.change1 <- run_LASSO(df,accuracy_change1) # age 65+, male, quebec, knowledge, polinterest, total media trust
lasso.canada.True7 <- run_LASSO(df,accuracy_True7) # University, Age 65, Ideology1, nonwhite, political interest, media_trust